import { defineComponent, ref } from "vue";
import styles from "./EnterpriseInformation.module.less";
import { ExclamationCircleFilled } from "@ant-design/icons-vue";
import { message } from "ant-design-vue";
import { useRouter } from "vue-router";
import { $userAuthentication } from "@/api/account/account";
import validateInstance from "@/libs/validate/validate";
export default defineComponent({
  name:'accountQyinformEnterpriseInformation',
  setup() {
    const router = useRouter();
    const baseInfo = ref({
      company_name: '',//企业名称
      code: null,//统一社会信用代码
      legal_person: null,//联系人姓名
      usual_mobile: null,//手机号
    });
    //提交
    const submit = () => {
      if (!baseInfo.value.company_name) {
        message.error('请填写企业信息')
        return;
      }
      if (!baseInfo.value.code) {
        message.error('请填写统一社会信用代码')
        return;
      }
      if (!baseInfo.value.legal_person) {
        message.error('请填写联系人姓名')
        return;
      }
      if (!baseInfo.value.usual_mobile) {
        message.error('请填写手机号')
        return;
      }
      if(!validateInstance.test(baseInfo.value.usual_mobile, "phone")){
        message.error('手机号格式错误,请重新填写')
        return;
      }
      $userAuthentication({
        name: baseInfo.value.company_name,
        code: String(baseInfo.value.code),
        contact_person: String(baseInfo.value.legal_person),
        contact_phone: String(baseInfo.value.usual_mobile),
      }).then((res: any) => {
        console.log(res)
        message.success('提交成功');
        router.push(`/account/Qyinform/Auditing?state=${10}`);
      })
    }
    return () => (
      <div class={styles['EnterpriseInformation']}>
        <div class={styles['tips']}>
          <span>温馨提示：</span>
          <span>1、修改企业名称/统一社会信用代码、许可证号需重新审核</span>
          <span>2、修改法人、联系人等信息，无需再次审核</span>
        </div>
        <div class={styles.container}>
          <div class={styles['form-box']}>
            <div class={styles['form-part']}>
              <div class={styles['form-title']}>企业基本信息</div>
              <a-form model={baseInfo.value} label-col={{ style: { width: '150px' } }}>
                <a-form-item
                  label="企业名称"
                  name="company_name"
                >
                  <a-input style={{ width: '500px' }} v-model:value={baseInfo.value.company_name} placeholder="请输入完整的企业名称或统一社会信用代码完善企业信息" />
                  <div class={styles['company_name-tips']}><ExclamationCircleFilled class={styles.icon} />未查询到企业信息时，直接输入企业名称即可</div>
                </a-form-item>
                <a-form-item
                  label="统一社会信用代码"
                  name="code"
                >
                  <a-input style={{ width: '500px' }} v-model:value={baseInfo.value.code} placeholder="统一社会信用代码" />
                </a-form-item>
                <a-form-item
                  label="联系人姓名"
                  name="legal_person"
                  required
                >
                  <a-input style={{ width: '500px' }} v-model:value={baseInfo.value.legal_person} placeholder="请输入姓名" />
                </a-form-item>
                <a-form-item
                  label="手机号码"
                  name="usual_mobile"
                  required
                >
                  <a-input style={{ width: '500px' }} v-model:value={baseInfo.value.usual_mobile} placeholder="请填写" />
                </a-form-item>
              </a-form>
            </div>
            <div class={styles['submit-btn']} onClick={() => submit()}>提交审核</div>
          </div>
        </div>
      </div>
    )
  }
})